package logic

import (
	"beike/houserpc/houserpc"
	"context"

	"beike/api/internal/svc"
	"beike/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type HouseListLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewHouseListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *HouseListLogic {
	return &HouseListLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *HouseListLogic) HouseList(req *types.HouseListRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line

	list, err := l.svcCtx.HouseRpc.HouseList(l.ctx, &houserpc.HouseListRequest{
		Page:           req.Page,
		Size:           req.Size,
		PriceOrder:     req.PriceOrder,
		CreatedAtOrder: req.CreatedAtOrder,
		Address:        req.City,
	})
	if err != nil {
		return &types.Response{
			Message: err.Error(),
			Data:    nil,
			Code:    0,
		}, nil
	}

	return &types.Response{
		Message: "展示成功",
		Data:    list,
		Code:    200,
	}, nil
}
